import Vue from 'vue'
import Vuex from 'vuex'
// 1. 导入包
import createPersistedState from 'vuex-persistedstate'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
  plugins: [createPersistedState()],
  state: {
    token: '',
    userInfo:{}
  },
  mutations: {
    updataToken(state, token) {
      state.token = token
     
    },
    updateUserInfo(state,payload) {
      state.userInfo= payload
    }
  },
  actions: {
    async getUserInfo(context) {
      const { data: res } = await axios.get('/my/userinfo')
      // console.log(res)
      if (res.code !== 0) return
      context.commit('updateUserInfo',res.data)
    }
  },
  
})
